import java.util.ArrayList;
import java.util.PriorityQueue;

public class Simulator {

	public static Policy policy = new Policy();
	private static PriorityQueue<EventBase> eventHeap = new PriorityQueue<EventBase>();
	public static ArrayList<PatientBase> patients = new ArrayList<PatientBase>();
	public static ArrayList<Triage> triage = new ArrayList<Triage>();
	public static ArrayList<Nurse> nurses = new ArrayList<Nurse>();
	public static ArrayList<Bed> beds = new ArrayList<Bed>();
	
	private static int currentTime = 1;
	private static int runLength = 100;
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("Starting Simulator...");
		
<<<<<<< .mine
//		// Initialize Resources
//		triage.add(new Triage()); // adds Triage 1
//		
//		beds.add(new Bed(1)); // adds bed 2
//		beds.add(new Bed(2)); // adds bed 3
////		beds.add(new Bed()); // adds bed 4
////		beds.add(new Bed()); // adds bed 5
////		beds.add(new Bed()); // adds bed 6
////		beds.add(new Bed()); // adds bed 7
////		beds.add(new Bed()); // adds bed 8
////		beds.add(new Bed()); // adds bed 9
////		beds.add(new Bed()); // adds bed 10
////		beds.add(new Bed()); // adds bed 11
////		beds.add(new Bed()); // adds bed 12
////		beds.add(new Bed()); // adds bed 13
////		beds.add(new Bed()); // adds bed 14
////		beds.add(new Bed()); // adds bed 15
////		beds.add(new Bed()); // adds bed 16
////		beds.add(new Bed()); // adds bed 17
////		beds.add(new Bed()); // adds bed 18
////		beds.add(new Bed()); // adds bed 19
////		beds.add(new Bed()); // adds bed 20
////		beds.add(new Bed()); // adds bed 21
//		
//		nurses.add(new Nurse("Judy", 1)); // adds zone 1 nurse
//		nurses.add(new Nurse("Karen", 2)); // adds zone 2 nurse
//		nurses.add(new Nurse("Kenneth", 3)); // adds zone 3 nurse
//		nurses.add(new Nurse("Amber", 4)); // adds zone 4 nurse
//		nurses.add(new Nurse("Heather", 5)); // adds zone 5 nurse
//		
=======
		// Initialize Resources
		triage.add(new Triage()); // adds Triage 1
		
		beds.add(new Bed(2)); // adds bed 2
		beds.add(new Bed(3)); // adds bed 3
//		beds.add(new Bed(4)); // adds bed 4
//		beds.add(new Bed(5)); // adds bed 5
//		beds.add(new Bed(6)); // adds bed 6
//		beds.add(new Bed(7)); // adds bed 7
//		beds.add(new Bed(8)); // adds bed 8
//		beds.add(new Bed(9)); // adds bed 9
//		beds.add(new Bed(10)); // adds bed 10
//		beds.add(new Bed(11)); // adds bed 11
//		beds.add(new Bed(12)); // adds bed 12
//		beds.add(new Bed(13)); // adds bed 13
//		beds.add(new Bed(14)); // adds bed 14
//		beds.add(new Bed(15)); // adds bed 15
//		beds.add(new Bed(16)); // adds bed 16
//		beds.add(new Bed(17)); // adds bed 17
//		beds.add(new Bed(18)); // adds bed 18
//		beds.add(new Bed(19)); // adds bed 19
//		beds.add(new Bed(20)); // adds bed 20
//		beds.add(new Bed(21)); // adds bed 21
		
		nurses.add(new Nurse("Judy", 1)); // adds zone 1 nurse
		nurses.add(new Nurse("Karen", 2)); // adds zone 2 nurse
		nurses.add(new Nurse("Kenneth", 3)); // adds zone 3 nurse
		nurses.add(new Nurse("Amber", 4)); // adds zone 4 nurse
		nurses.add(new Nurse("Heather", 5)); // adds zone 5 nurse
		
>>>>>>> .r49
		// Schedule Patient Arrivals
		eventHeap.add(new PatientArrivesEvent(1, new HipPatient(1, 1, 3, false, false, false)));
		eventHeap.add(new PatientArrivesEvent(5, new HipPatient(2, 5, 4, false, false, false)));
		
		// Simulator Loop

		while(currentTime < runLength && !eventHeap.isEmpty()) {
			System.out.println("Time: " + currentTime);
			policy.evaluate(patients); 						// this adds all necessary events
			EventBase nextEvent = eventHeap.poll();
			
			if(nextEvent.getStartTime() < currentTime)
				throw new Exception("Can't schedule event in the past!");
			
			currentTime = nextEvent.getStartTime();
			nextEvent.execute();
			policy.evaluate(patients); 						// this adds all necessary events
			policy.nurseEvaluation(patients);
		}
		System.out.println("End Simulator..." + currentTime);
	}
	
	public static int getCurrentTime() {
		return currentTime;
	}
	
	public static void addEvent(EventBase event) {
		if(!eventHeap.contains(event)) {
			event.setInHeap(true);
			eventHeap.add(event);
		}
	}
	
	public static void addEvents(ArrayList<EventBase> events) {
			eventHeap.addAll(events);
	}
	
	public static void addPatient(PatientBase patient) {
		patients.add(patient);
	}
}
